package com.tc.dispatch.aa.util;

import com.tc.dispatch.aa.dao.*;
import com.tc.dispatch.aa.exception.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: ZJU</p>
 * @author DxFeng
 * @version 2.0
 */

public class DAOFactory
{
    private DAOFactory(){
    }

    public static RoleDAO getRoleDAO() throws AASysException
    {
        try
        {
            ServiceLocator sl = new ServiceLocator();
            String roleDAOClassName = sl.getString(JNDINames.ROLE_DAO_CLASS);
            return (RoleDAO) Class.forName(roleDAOClassName).newInstance();
        }
        catch (Exception ex)
        {
            throw new AASysException("Exception found.", ex);
        }
    }
    public static UserDAO getUserDAO() throws AASysException
    {
        try
        {
            ServiceLocator sl = new ServiceLocator();
            String userDAOClassName = sl.getString(JNDINames.USER_DAO_CLASS);
            return (UserDAO) Class.forName(userDAOClassName).newInstance();
        }
        catch (Exception ex)
        {
            throw new AASysException("Exception found.", ex);
        }
    }
    public static ResourceDAO getResourceDAO() throws AASysException
    {
        try
        {
            ServiceLocator sl = new ServiceLocator();
            String resourceDAOClassName = sl.getString(JNDINames.RESOURCE_DAO_CLASS);
            return (ResourceDAO) Class.forName(resourceDAOClassName).newInstance();
        }
        catch (Exception ex)
        {
            throw new AASysException("Exception found.", ex);
        }
    }
    public static ActionDAO getActionDAO() throws AASysException
    {
        try
        {
            ServiceLocator sl = new ServiceLocator();
            String actionDAOClassName = sl.getString(JNDINames.ACTION_DAO_CLASS);
            return (ActionDAO) Class.forName(actionDAOClassName).newInstance();
        }
        catch (Exception ex)
        {
            throw new AASysException("Exception found.", ex);
        }
    }

    public static RelUserRoleDAO getRelUserRoleDAO() throws AASysException
    {
        try
        {
            ServiceLocator sl = new ServiceLocator();
            String relUserRoleDAOClassName = sl.getString(JNDINames.REL_USER_ROLE_DAO_CLASS);
            return (RelUserRoleDAO) Class.forName(relUserRoleDAOClassName).newInstance();
        }
        catch (Exception ex)
        {
            throw new AASysException("Exception found.", ex);
        }
    }

    public static RelRuleDAO getRelRuleDAO() throws AASysException
    {
        try
        {
            ServiceLocator sl = new ServiceLocator();
            String relRuleDAOClassName = sl.getString(JNDINames.REL_RULE_DAO_CLASS);
            return (RelRuleDAO) Class.forName(relRuleDAOClassName).newInstance();
        }
        catch (Exception ex)
        {
            throw new AASysException("Exception found.", ex);
        }
    }

}

























